<?php
// 提交添加医生信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");

$n_docID = $_POST["docID"];
$n_docName = $_POST["docName"];
$n_docPhone = $_POST["docPhone"];
$n_defaultPwd = $_POST["defaultPwd"];
$n_docMainType = $_POST["docMainType"];
$n_docAccept = $_POST["docAccept"];

$n_docPhoto = $_FILES['docPhoto'];

if (!in_array($n_docPhoto['type'], ['image/jpg', 'image/jpeg', 'image/png'])) {
    die("<script>alert('图片格式错误！请重新选择！');history.go(-1);</script>");
}

if ($n_docPhoto['size'] > 2000000) {
    die("<script>alert('图片大小错误！大小不能超过2M！请重新选择！');history.go(-1);</script>");
}

// 图片上传路径
$uploadAddress = "../public/pic/doc_imgs/";
// 图片名称
$photoName = $n_docID . "." . pathinfo($n_docPhoto['name'], PATHINFO_EXTENSION);
// 完整路径
$upload = $uploadAddress . $photoName;

if (move_uploaded_file($n_docPhoto['tmp_name'], $upload)) {
    $insert_addinfo = "INSERT INTO doc_infos (doc_ID, doc_Name, doc_Password, doc_TypeMain, doc_PhotoAddress, doc_Accept, doc_Phone)
    VALUES ('" . $n_docID . "', '" . $n_docName . "', '" . $n_defaultPwd . "', '" . $n_docMainType . "','".$photoName."', '" . $n_docAccept . "', '" . $n_docPhone . "')";
    if (mysqli_query($connect_DB, $insert_addinfo)) {
        echo "<script>alert('添加医生信息成功！');location='admin_AddDoctor.php';</script>";
    } else {
        unlink($upload);
        die("<script>alert('添加医生信息失败！请重试！');</script>");
    }
} else {
    die("<script>alert('医生照片上传失败！请重试！');history.go(-1);</script>");
}

$connect_DB->close();
?>